/*     */ package com.zimbra.cs.index;
/*     */ 
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.text.ParseException;
/*     */ import java.util.Date;
/*     */ import org.apache.lucene.document.DateTools;
/*     */ import org.apache.lucene.document.Document;
/*     */ import org.apache.lucene.index.IndexReader;
/*     */ import org.apache.lucene.store.Directory;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class RawIndexEditor
/*     */ {
/*     */   private final Directory luceneDirectory;
/*     */   
/*     */   RawIndexEditor(String path)
/*     */     throws IOException
/*     */   {
/*  33 */     this.luceneDirectory = LuceneDirectory.open(new File(path));
/*     */   }
/*     */   
/*     */   public static String Format(String s, int len) {
/*  37 */     StringBuffer toRet = new StringBuffer(len + 1);
/*  38 */     int curOff = 0;
/*  39 */     if (s.length() < len) {
/*  40 */       for (curOff = 0; curOff < len - s.length(); curOff++) {
/*  41 */         toRet.append(" ");
/*     */       }
/*     */     }
/*     */     
/*  45 */     int sOff = 0;
/*  46 */     for (; curOff < len; curOff++) {
/*  47 */       toRet.append(s.charAt(sOff));
/*  48 */       sOff++;
/*     */     }
/*  50 */     toRet.append("  ");
/*  51 */     return toRet.toString();
/*     */   }
/*     */   
/*     */   public boolean dumpDocument(Document doc, boolean isDeleted) {
/*  55 */     if (isDeleted) {
/*  56 */       System.out.print("DELETED ");
/*     */     }
/*  58 */     String subject = doc.get("subject");
/*  59 */     if (subject == null) {
/*  60 */       subject = "MISSING_SUBJECT";
/*     */     }
/*  62 */     String blobId = doc.get("l.mbox_blob_id");
/*  63 */     if (blobId == null) {
/*  64 */       blobId = "MISSING";
/*     */     }
/*  66 */     String part = doc.get("l.partname");
/*  67 */     if (part == null) {
/*  68 */       part = "NULL_PART";
/*     */     }
/*     */     
/*  71 */     String dateStr = doc.get("l.date");
/*  72 */     if (dateStr == null) {
/*  73 */       dateStr = "";
/*     */     } else {
/*     */       try {
/*  76 */         dateStr = DateTools.stringToDate(dateStr).toString();
/*     */       } catch (ParseException e) {
/*  78 */         if (!$assertionsDisabled) throw new AssertionError();
/*     */       }
/*     */     }
/*  81 */     String sizeStr = doc.get("l.size");
/*  82 */     if (sizeStr == null) {
/*  83 */       sizeStr = "";
/*     */     }
/*     */     
/*  86 */     System.out.println(Format(blobId, 10) + Format(dateStr, 30) + Format(part, 10) + Format(sizeStr, 10) + "\"" + subject + "\"");
/*     */     
/*     */ 
/*  89 */     return true;
/*     */   }
/*     */   
/*     */   void dumpAll() throws IOException
/*     */   {
/*  94 */     IndexReader reader = IndexReader.open(this.luceneDirectory);
/*     */     try {
/*  96 */       int maxDoc = reader.maxDoc();
/*  97 */       System.out.println("There are " + maxDoc + " documents in this index.");
/*     */       
/*  99 */       for (int i = 0; i < maxDoc; i++) {
/* 100 */         dumpDocument(reader.document(i), reader.isDeleted(i));
/*     */       }
/*     */     } finally {
/* 103 */       reader.close();
/*     */     }
/*     */   }
/*     */   
/*     */   void run() throws IOException {
/* 108 */     dumpAll();
/*     */   }
/*     */   
/*     */   public static void main(String[] args) {
/* 112 */     String idxParentDir = args[0];
/*     */     try
/*     */     {
/* 115 */       RawIndexEditor editor = new RawIndexEditor(idxParentDir);
/* 116 */       editor.run();
/*     */     } catch (IOException e) {
/* 118 */       System.err.println("Caught IOException " + e);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/RawIndexEditor.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */